package com.ctjsoft.threadstatus;

/**
 * 测试线程状态
 *
 * @author liaoyy
 * @date Created in 2022/1/10 21:53
 */
public class ThreadStateDemo implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 2; i++) {
            System.out.println("线程----");
        }
    }


    public static void main(String[] args) {
        ThreadStateDemo threadStateDemo = new ThreadStateDemo();
        Thread thread = new Thread(threadStateDemo);

        Thread.State state = thread.getState();
        System.out.println(state);

        thread.start();
        state = thread.getState();
        System.out.println(state);

        while (state != Thread.State.TERMINATED){
            System.out.println(state);
            state = thread.getState();
        }
    }
}
